package com.example.es.config;

import com.example.es.entity.Promotion;
import com.example.es.service.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class DataInitializer implements CommandLineRunner {

    @Autowired
    private PromotionService promotionService;

    @Override
    public void run(String... args) throws Exception {
        // 初始化一些测试数据
        Promotion promotion1 = new Promotion(
            "双十一大促",
            "年度最大促销活动，全场商品5折起",
            LocalDateTime.of(2025, 11, 1, 0, 0),
            LocalDateTime.of(2025, 11, 11, 23, 59),
            0.5,
            "seasonal",
            "双十一,大促,折扣"
        );

        Promotion promotion2 = new Promotion(
            "新用户专享",
            "新注册用户享受8折优惠",
            LocalDateTime.now().minusDays(1),
            LocalDateTime.now().plusMonths(1),
            0.8,
            "new_user",
            "新用户,专享,优惠"
        );

        Promotion promotion3 = new Promotion(
            "会员日特惠",
            "每月15日会员专属7折优惠",
            LocalDateTime.of(2025, 10, 15, 0, 0),
            LocalDateTime.of(2025, 10, 15, 23, 59),
            0.7,
            "member",
            "会员,特惠,专属"
        );

        Promotion promotion4 = new Promotion(
            "清仓甩卖",
            "库存清理，部分商品3折起",
            LocalDateTime.now().minusDays(7),
            LocalDateTime.now().plusDays(30),
            0.3,
            "clearance",
            "清仓,甩卖,特价"
        );

        promotionService.save(promotion1);
        promotionService.save(promotion2);
        promotionService.save(promotion3);
        promotionService.save(promotion4);

        System.out.println("初始化促销活动数据完成");
    }
}